﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DAL;
using System.Data.SqlClient;

public class CMSUser : Frame.BaseModel.FUser
{
    private CMSUser()
    {
    }
    string[] Rights;
    public static bool Login(string LoginName, string Pwd, string UserName)
    {
        using (DataClassesDataContext dc = new DataClassesDataContext())
        {
            string aa = dc.Connection.ConnectionString;
            User u = dc.User.FirstOrDefault(o => o.LoginName == LoginName && o.PassWord == Pwd || o.UserName == UserName);
            if (u == null)
            {
                return false;
            }
            else
            {
                Current = new CMSUser()
                {
                    ID = u.ID,
                    IsAdmin = (u.IsAdmin == 1),
                    m_isLogin = true,
                    Name = u.UserName,
                    Rights = u.Rights.Split('|'),
                };
                return true;
            }
        }
    }

    public override bool CheckActionAllow(string ActionID)
    {
        if (!this.IsLogin)//当前是否登录用户
        {
            return false;
        }
        else
        {
            if (IsAdmin)//管理员账号，权限全开
            {
                return true;
            }
            else//其他人员的权限待补充
            {
                return Rights.Contains(ActionID);
            }
        }
    }
}